package com.tanhua.manage.listener;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tanhua.domain.mongo.Publish;
import com.tanhua.manage.domain.Log;
import com.tanhua.manage.service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.yetus.audience.InterfaceAudience;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArithmeticOperators;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@RocketMQMessageListener(topic = "tanhua_log", consumerGroup = "tanhua_log_consumer")
@Slf4j
public class LogMessageListener implements RocketMQListener<String> {
    @Autowired
    private LogService logService;

    @Override
    public void onMessage(String josnString) {
      log.info("LogMessage:记录日志"+josnString);
        JSONObject jsonObject = JSON.parseObject(josnString);
        Log log = new Log();
        log.setCreated(new Date());
        log.setUserId(jsonObject.getLong("userId"));
        log.setLogTime(jsonObject.getString("log_time"));
        log.setType(jsonObject.getString("type"));
        log.setEquipment(jsonObject.getString("equipment"));
        log.setPlace(jsonObject.getString("place"));
        logService.add(log);
    }
}
